package com.zb.testview;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends ActionBarActivity {

    private View mv;
    private View view;

    @Override
    public void onAttachedToWindow() {
        Log.i("0504", " .............. onAttachedToWindow.....................之前");
        super.onAttachedToWindow();
        Log.i("0504", " .............. onAttachedToWindow.....................之后");
    }

    @Override
    public void onDetachedFromWindow() {
        Log.i("0504", " .............. onDetachedFromWindow.....................之前");
        super.onDetachedFromWindow();
        Log.i("0504", " .............. onDetachedFromWindow.....................之后");
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        Log.i("0504", " .............. onWindowFocusChanged.....................之前 hasFocus = " + hasFocus);
        super.onWindowFocusChanged(hasFocus);
        Log.i("0504", " .............. onWindowFocusChanged.....................之后 hasFocus = " + hasFocus);
    }

//    @Override
//    public void onWindowAttributesChanged(WindowManager.LayoutParams params) {
//        Log.i("0504", " .............. onWindowAttributesChanged.....................");
//        super.onWindowAttributesChanged(params);
//    }

//    @Override
//    public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
//        Log.i("0504", " .............. onCreateView.....................");
//        return super.onCreateView(parent, name, context, attrs);
//    }

    @Override
    protected void onUserLeaveHint() {
        Log.i("0504", " .............. onUserLeaveHint.....................");
        super.onUserLeaveHint();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.i("0504", " .............. onCreate....................setContent 之前");
        setContentView(R.layout.activity_main);

        view = findViewById(R.id.mv);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(MainActivity.this, "short click!", Toast.LENGTH_SHORT).show();
            }
        });

        view.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                Toast.makeText(MainActivity.this, "long click!", Toast.LENGTH_SHORT).show();
                return true;
            }
        });

        //testSourceTree
        String  s = "啪啪啪";

        String  s2 = "123";

//        int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(30, View.MeasureSpec.EXACTLY);
        String s2 = "abc";
//        int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(30, View.MeasureSpec.EXACTLY);
//        view.measure(widthMeasureSpec, heightMeasureSpec);

//        int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec((1 << 30) - 1, View.MeasureSpec.AT_MOST);
//        int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec((1 << 30) - 1, View.MeasureSpec.AT_MOST);
//        view.measure(widthMeasureSpec, heightMeasureSpec);

//        int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
//        int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
//        view.measure(widthMeasureSpec, heightMeasureSpec);


        view.post(new Runnable() {
            @Override
            public void run() {
                Log.i("0504", "width = " + view.getWidth());
                Log.i("0504", "height = " + view.getHeight());
                Log.i("0504", "measuredWidth = " + view.getMeasuredWidth());
                Log.i("0504", "measuredHeight = " + view.getMeasuredHeight());
            }
        });




        Log.i("0504", " .............. onCreate....................setContent 之后");
    }

    @Override
    protected void onStart() {
        Log.i("0504", " .............. onStart.....................之前");
        super.onStart();
        Log.i("0504", " .............. onStart.....................之后");
    }

    @Override
    protected void onRestart() {
        Log.i("0504", " .............. onRestart.....................之前");
        super.onRestart();
        Log.i("0504", " .............. 0000.....................之后");
    }

    @Override
    protected void onResume() {

        //哈哈222
        Log.i("0504", " .............. onResume.....................之前");
        super.onResume();
        Log.i("0504", " .............. onResume.....................之后");
    }

    @Override
    protected void onPause() {
        Log.i("0504", " .............. onPause.....................之前");
        super.onPause();
        Log.i("0504", " .............. onPause.....................之后");
    }

    @Override
    protected void onStop() {
        Log.i("0504", " .............. onStop.....................之前");
        super.onStop();
        Log.i("0504", " .............. onStop.....................之后");
    }

    @Override
    protected void onDestroy() {
        Log.i("0504", " .............. onDestroy.....................之前");
        super.onDestroy();
        Log.i("0504", " .............. onDestroy.....................之后");
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        Log.v("0504", "................... dispatchTouchEvent.....................");
        return super.dispatchTouchEvent(ev);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        Log.v("0504", "................... onTouchEvent.....................");
        return super.onTouchEvent(event);
    }

    public boolean onKeyDown(int keyCode, KeyEvent event) {
        Log.v("0504", "................... onKeyDown.....................");
        return super.onKeyDown(keyCode, event);
    }
}
